Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site screenshot: Add responsive image support to the screenshot block #175

Merged
merged 7 commits into from
Sep 27, 2023

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Sep 22, 2023

Fixes #156. This adds a new attribute to the screenshot block, location. This passes a hint to the block about where the image will be used, so that we can set location-aware responsive image hints. When location is grid|row (related sites), the block now adds srcset/sizes attributes.

This PR also sets up a few new image sizes from 500-1400px wide, which covers the different sizes the images are shown in the grid. Locally you can regenerate these with wp media regenerate, but sandboxes & production will use Photon and dynamically load the right size.

Using smaller (height/width) images decreases the filesizes, so most images are under 500KB now even on retina screens.

This also fixes #171, because changing that later would require changing the sizes value too.

To test

  • View anywhere the site screenshot is displayed, there should be no visible difference and no image quality change.
  • Images in the site grid should have srcset and sizes attributes
  • If you watch the network tab, the image loaded should reflect the column size (and screen resolution).

@ryelle ryelle added the [Component] Blocks/Editor Custom blocks, block variations, or editor customization label Sep 22, 2023
@ryelle ryelle self-assigned this Sep 22, 2023
@ryelle ryelle marked this pull request as ready for review September 25, 2023 15:18
@ryelle ryelle force-pushed the update/screenshots-image-size branch from fd12814 to a05909e Compare September 25, 2023 15:19
Copy link
Contributor

@adamwoodnz adamwoodnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Working for me in the grid.

Is there a reason not to do it on the single site page? At mobile size it looks like we're still loading the largest size:

Screenshot 2023-09-27 at 3 08 25 PM

sandboxes & production will use Photon and dynamically load the right size

Want to make sure I understand this, does photon look at the srcset and sizes and set the src appropriately?

Copy link
Collaborator

@StevenDufresne StevenDufresne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement.

Copy link
Contributor

@renintw renintw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me 👍 I can see the srcset and sizes in grid and row.

image

@ryelle
Copy link
Contributor Author

ryelle commented Sep 27, 2023

Is there a reason not to do it on the single site page? At mobile size it looks like we're still loading the largest size:

No, I just focused on grid pages first, having the most images and therefore highest impact. It could be updated to work on single sites in the future, all that's needed is to figure out what the sizes & srcsets should be.

Want to make sure I understand this, does photon look at the srcset and sizes and set the src appropriately?

No, this is just about generating those image URLs. Photon hooks into the way WP generates media URLs and replaces them, so when you call for an image that's 100x100, it will automatically add resize=100,100 to the returned URL. So it doesn't matter if the local site has generated that image, the CDN will resize automatically.

@ryelle ryelle merged commit 232f6f0 into main Sep 27, 2023
1 check passed
@ryelle ryelle deleted the update/screenshots-image-size branch September 27, 2023 15:39
@StevenDufresne
Copy link
Collaborator

I was navigating around the site on staging and found the single pages were pretty slow to load.

Can we update them? The related sites contribute to the slowness.

Page: https://wordpress.org/showcase-v2/opus-one/
Screenshot 2023-10-04 at 12 09 10 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Blocks/Editor Custom blocks, block variations, or editor customization
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Breakpoint change Images seem larger than they need to be.
4 participants